#ifndef PERIPHERALS_H_INCLUDED
#define PERIPHERALS_H_INCLUDED


#include "Utils.h"
#include "WavPlayer.h"

#define MOSI_DDR    DDRB
#define MISO_DDR    DDRB
#define RST_DDR     DDRC // ?
#define SCK_DDR     DDRB
#define CS_DDR      DDRB
#define LEDR_DDR	DDRB
#define LEDG_DDR	DDRD
#define LEDB_DDR	DDRB
#define SPK_DDR     DDRB
#define DBLED_DDR 	DDRD

#define MOSI_PINNUM     2
#define MISO_PINNUM     3
#define RST_PINNUM      6
#define SCK_PINNUM      1
#define CS_PINNUM       0
#define LEDR_PINNUM		7
#define LEDG_PINNUM     0
#define LEDB_PINNUM		5
#define SPK_PINNUM      6
#define DBLED_PINNUM	5

#define MOSI_PORT   PORTB
#define MISO_PORT   PORTB
#define RST_PORT    PORTC
#define SCK_PORT    PORTB
#define CS_PORT     PORTB
#define LEDR_PORT	PORTB
#define LEDG_PORT   PORTD
#define LEDB_PORT	PORTB
#define SPK_PORT    PORTB
#define DBLED_PORT	PORTD

#define MOSI_PIN    PINB
#define MISO_PIN    PINB
#define RST_PIN     PINC
#define SCK_PIN     PINB
#define CS_PIN      PINB
#define LEDR_PIN	PINB
#define LEDG_PIN    PIND
#define LEDB_PIN	PINB
#define SPK_PIN     PINB
#define DBLED_PIN	PIND


#define RED     OCR1C
#define GREEN   OCR0B
#define BLUE    OCR1A

#define SPK_OUT OCR1B
#define PLAYBACK_RATE OCR3A

#define IRLED_DDR		DDRE
#define IRLED_PORT		PORTE
#define IRLED_PINNUM	6

#define IRT_ADC    0;//(0 << MUX3) | (0 << MUX2) | (0 << MUX1) | (0 << MUX0)
#define NO_ADC     (0 << MUX3) | (0 << MUX2) | (0 << MUX1) | (0 << MUX0)

void setupPeripherals(void);
void InitIO(void);
void InitClock(void);
void InitPWM(void);
void blinkBlue(void);
void blinkGreen(void);

void IrLedOn();
void IrLedOff();
void InitADC(void);
void getADC(uint16_t *val);

#endif // PERIPHERALS_H_INCLUDED
